package com.helmlabs.grouper.cms.model;

import java.util.List;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

@Entity
public class MenuItem {
	
	private Long id;
	private String display;
	private Menu menu;
	private int menuOrder;
	private Long pageId;
	private MenuItem parent;
	private List<MenuItem> subItems;

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public int getMenuOrder() {
		return menuOrder;
	}
	public void setMenuOrder(int menuOrder) {
		this.menuOrder = menuOrder;
	}
	public Long getPageId() {
		return pageId;
	}
	public void setPageId(Long pageId) {
		this.pageId = pageId;
	}
	public String getDisplay() {
		return display;
	}
	public void setDisplay(String display) {
		this.display = display;
	}
	
	@ManyToOne
	public MenuItem getParent(){
		return this.parent;
	}
	
	public void setParent(MenuItem parent){
		this.parent = parent;
	}
	
	@OneToMany(mappedBy="parent",fetch=FetchType.EAGER)
	public List<MenuItem> getSubItems() {
		return subItems;
	}
	public void setSubItems(List<MenuItem> subItems) {
		this.subItems = subItems;
	}
	
	@ManyToOne
	public Menu getMenu() {
		return menu;
	}
	public void setMenu(Menu menu) {
		this.menu = menu;
	}
	public String toLink(){
		return "<a href=\"page\\" + getPageId() + "\\\">" + getDisplay() + "</a>";
	}

}
